package com.spirngcloud.alibabasentinelratelimiting.controller.mq.util;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/23 21:35
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/23
 * @Modify marker：
 **/
@Configuration
public class FanoutExchangeConfig {

    /**
     * 注入Fanout路由策略
     * @return
     */
    @Bean(name="myFanoutExchange")
    FanoutExchange getFanoutExchange(){
        return new FanoutExchange("My-Fanout-Exchange");
    }
    @Bean
    Binding bindingQueueToFanoutExchange(@Qualifier("myFirstQueue")Queue myFirstQuue,
                                         @Qualifier("myFanoutExchange") FanoutExchange myFanoutExchange){
        return BindingBuilder.bind(myFirstQuue).to(myFanoutExchange);
    }
    @Bean
    Binding BindingQueueTwoToFanoutExchange(@Qualifier("myTwoQueue") Queue myTwoQueue,
                                            @Qualifier("myFanoutExchange") FanoutExchange myFanout){
        return BindingBuilder.bind(myTwoQueue).to(myFanout);
    }

    @Bean
    Binding BindingQueueThrFanoutExchange(@Qualifier("myThreeQueue") Queue myThreeQueue,
                                          @Qualifier("myFanoutExchange") FanoutExchange myFanout){
        return  BindingBuilder.bind(myThreeQueue).to(myFanout);
    }
}
